﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HeroDream
{
    class Hero
    {
        private string name;

        protected int coin;

        public int Coin
        {
            get
            {
                return coin;
            }
            set
            {
                int addValue = value - coin;
                coin = value;
                Console.WriteLine($"恭喜玩家{name}获得金币{addValue}");
            }
        }

        public int age;

        private int fight;


        private List<Equipment> equipments = new List<Equipment>();

        /// <summary>
        /// 只有返回数据的属性器，封装变量，保护数据安全性
        /// </summary>
        public string Name => name;

        public Hero(string name)
        {
            this.name = name;
            Random random = new Random(DateTime.Now.Millisecond);
            Coin = random.Next(100);
            age = 1;
            fight = random.Next(1,20);
            Console.WriteLine($"公元100年，{name}出生在天南大路......");
        }


        public void OutPut()
        {
            Console.WriteLine($"我叫{name}，今年{age}岁，拥有金币{Coin}，战斗力为{fight}");
        }

        public void DoTask(Task task)
        {
            if (age > 100)
            {
                Console.WriteLine("暂时无法接取任务");
            }
            else
            {
                task.TaskRun(this);
                Console.WriteLine($"恭喜{Name}完成任务:");
            }
        }

        public void EquipItem(Equipment equipment)
        {
            equipments.Add(equipment);
        }

        public Equipment GetEquip(int index)
        {
            return equipments[index];
        }

        public void RemoveEquip(string name)
        {
           for(int i = 0; i < equipments.Count; i++)
            {
                if (equipments[i].Name == name)
                {
                    equipments.RemoveAt(i);
                    break;
                }
            }
        }

        //合成装备：选择要合成的装备 int a,int b
        //生成新的装备，把旧装备删除，新装备加入装备栏
        //装备相加 攻击力相加，金币相加，名字修改为"（合成）（namea+nameb）"
        //可合成装备、角色、怪物合并等相关功能。

        public void CombineEquip()
        {
            Console.WriteLine("请输入你要合并的装备编号a和b,用空格隔开");
            string s = Console.ReadLine();
             string[] ss= s.Split(' ');
            int a = Convert.ToInt32(ss[0]);
            int b = Convert.ToInt32(ss[1]);
            Equipment qa = GetEquip(a);
            Equipment qb = GetEquip(b);
            Equipment com = qa + qb;
            RemoveEquip(qa.Name);
            RemoveEquip(qb.Name);
            EquipItem(com);
        }
    }
}
